package com.marry.core.utils;

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

/**
 * @path：com.marry.common.core.utils.DateUtil.java
 * @className：DateUtil.java
 * @description：时间转换工具类
 * @author：LiuYun
 * @dateTime：2021/06/29 22:32
 * @editNote：
 */
public class DateUtil {

    /**
     * 获取日期的整数形式
     * @return
     */
    public static Long getDate(){
        return getDate(LocalDateTime.now());
    }

    /**
     * 获取日期的整数形式
     * @param now
     * @return
     */
    public static Long getDate(LocalDateTime now){
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        return year*10000L + month*100L + day;
    }

    /**
     * 获取时间的整数形式
     * @return
     */
    public static Long getTime(){
        return getTime(LocalDateTime.now());
    }

    /**
     * 获取时间的整数形式
     * @param now
     * @return
     */
    public static Long getTime(LocalDateTime now){
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();
        int millions = now.get(ChronoField.MILLI_OF_SECOND);
        return hour*10000000L + minute*100000L + second*1000L + millions;
    }
}
